package com.itheima.service.umsService.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.domain.db.ums.UmsResourceCategory;
import com.itheima.mapper.umsMapper.UmsResourceCategoryMapper;
import com.itheima.service.umsService.UmsResourceCategoryService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UmsResourceCategoryServiceImpl implements UmsResourceCategoryService {

    @Autowired
    private UmsResourceCategoryMapper umsResourceCategoryMapper;

    /**
     * 增加资源分类
     *
     * @param umsResourceCategory
     */
    @Override
    public void addResourceCategory(UmsResourceCategory umsResourceCategory) {
        umsResourceCategoryMapper.insert(umsResourceCategory);
    }

    /**
     * 根据id删除资源分类
     *
     * @param id
     */
    @Override
    public void deleteResourceCategory(Integer id) {
        umsResourceCategoryMapper.deleteById(id);
    }


    /**
     * 修改资源分类
     *
     * @param id
     */

    @Override
    public void updateResourceCategory(Integer id, UmsResourceCategory umsResourceCategory) {
        LambdaQueryWrapper<UmsResourceCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UmsResourceCategory::getId, id);
        umsResourceCategoryMapper.update(umsResourceCategory, queryWrapper);

    }


    /**
     * 获取所有资源分类
     *
     * @return
     */
    @Override
    public List<UmsResourceCategory> selectResourceCategoryList() {
        // 查询所有资源分类
        List<UmsResourceCategory> umsResourceCategories = umsResourceCategoryMapper.selectList(null);
        return umsResourceCategories;
    }


}
